<?php
 /**
 * 连接Redis服务器基类
 *
 * LICENSE:
 * @author $Id$
 * @since      Release 1.0.0
 * @copyright  Copyright (c) 2010-2011 Mumayi.com Inc. (http://www.mumayi.com)
*/
class Custom_Controller_Plugin_Mredis extends Zend_Controller_Plugin_Abstract
{

	private $ip='172.16.228.204';

	private $port=6379;

	private $password="mu#*!*mayi@&*()DATa";

	public 	$prefix='jindan_';

	function __construct($ip='172.16.228.204',$port=6379,$password="mu#*!*mayi@&*()DATa"){
		if(isset($ip))$this->ip=$ip;
		if(isset($port))$this->port=$port;
		//if(isset($password))$this->password=$password;

	}

	public function init(){

		try {
			//连接redis服务器
			$this->redis = new Redis();
			$result=$this->redis->connect($this->ip,$this->port);
			return true;
		} catch (Exception $e) {
			return false;
        }
	}


	//把key为$id的值,存入缓存
	function redisSet($id,$content){
		$id=$this->prefix.$id;
		$result=$this->redis->set($id, $content);
		return $result;
	}


	//把key为$id的值,存入缓存
	function redisTimeSet($id,$time,$content){
		$id=$this->prefix.$id;
		$result=$this->redis->setex($id,$time,$content);
		return $result;
	}


	//取到key为$id的值
	function redisGet($id){
		$id=$this->prefix.$id;
		$result=$this->redis->get($id);
		return $result;
	}



}